<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="This is my page">
	
	<base target="_self">
  </head>
  
  <body>
    <center>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'新增码表'}]"/>
    			<jsp:param name="width" value="50%"/>
    		</jsp:include>
    		
    		<s:hidden name="ct.paper.id" id="paperId"></s:hidden>
    		
    		<table cellspacing="1" cellpadding="3" bgcolor="#CCCCCC" width="100%">
    			<tr bgcolor="#FFFFFF">
    				<td width="20%" class="label" align="right">
    					编码：
    				</td>
    				<td width="30%" align="left">
   						<s:textfield name="ct.code" id="code" cssStyle="width:100px;" maxlength="10"></s:textfield>
    				</td>
    				<td width="20%" class="label" align="right">
    					类型：
    				</td>
    				<td width="30%" align="left">
   						<s:select list='#{"codeTable":"码表", "groupQes":"组题"}' name="ct.ctType" id="ctType" cssStyle="width:100px;" onchange="ctTypeChange()"></s:select>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td class="label" align="right">
    					描述：
    				</td>
    				<td align="left" colspan="3">
    					<s:textarea name="ct.description" id="description" cssStyle="width:95%; height:80px;"></s:textarea>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF" id="halfQesTr">
    				<td class="label" align="right">
    					是否半开放题：
    				</td>
    				<td align="left">
   						<input type="checkbox" value="Y" name="ct.hasHalfQes" id="hasHalfQes" onclick="halfQesClick()" />
    				</td>
    				<td class="label" align="right" width="20%">
    					半开放题值：
    				</td>
    				<td align="left">
    					<s:textfield name="ct.halfQesVal" id="halfQesVal" cssStyle="width:100px;" maxlength="5" readonly="true"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF" id="halfQesTr">
    				<td class="label" align="right">
    					半开放题宽度：
    				</td>
    				<td align="left">
   						<s:select list="commonList" listKey="value" listValue="label" cssStyle="width:90px;" name="ct.halfQesWidth" id="halfQesWidth"></s:select>
    				</td>
    				<td class="label" align="right" width="20%">
    					半开放题个数：
    				</td>
    				<td align="left">
    					<s:select list="commonList" listKey="value" listValue="label" cssStyle="width:90px;" name="ct.halfQesQuantity" id="halfQesQuantity"></s:select>
    				</td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" value="保存" class="btn" onclick="saveThis()" />
    				</td>
    			</tr>
    		</table>
    	</s:form>
    </center>
    
    <script type="text/javascript">
    function saveThis()
    {
    	var code = $('#code');
    	var description = $('#description');
    	var hasHalfQes = $('#hasHalfQes');
    	var halfQesVal = $('#halfQesVal');
    	if(!isNotNull(code.val()))
    	{
    		showMsg('编码不能为空。', function(){code.focus();});
    		return;
    	}
    	if(description.val().length > 200)
    	{
    		showMsg('描述不能超过200字。', function(){description.focus();});
    		return;
    	}
    	if(!isNotNull(halfQesVal.val()) && hasHalfQes.attr('checked'))
    	{
    		showMsg('请填写半开放题值。', function(){halfQesVal.focus();});
    		return;
    	}
    	
    	ajaxAction('inner/qes/addCodeTable.action', 'post', 'frm', true, function(obj){
    		if('hasCode' == obj.result)
    		{
    			showMsg('已存在该码表编码。', function(){code.focus();});
    		}
    		else
    		{
    			showMsg('保存成功。', function(){
    				var pWin = getParentWin();
    				var codeTableId = pWin.$('#codeTableId');
    				var groupQes = pWin.$('#groupQes');
    				var initValue = codeTableId.val();
    				var groupQesVal = groupQes.val();
    				if('codeTable' == obj.ctType)
    				{
	    				addSelectOption2(codeTableId, obj.ctList, 'id', 'code', true);
	    				if(isNotNull(initValue))
	    				{
	    					codeTableId.val(initValue);
	    				}
    				}
    				else if('groupQes' == obj.ctType)
    				{
    					addSelectOption2(groupQes, obj.ctList, 'id', 'code', true);
	    				if(isNotNull(groupQesVal))
	    				{
	    					groupQes.val(groupQesVal);
	    				}
    				}
    				var url = realPath + '/inner/qes/toUpdateCodeTable.action?ct.id=' + obj.id;
    				document.forms['frm'].action = url;
    				document.forms['frm'].submit();
    			});
    		}
    	});
    }
    
    function halfQesClick()
    {
    	var hasHalfQes = $('#hasHalfQes');
    	var halfQesVal = $('#halfQesVal');
    	var halfQesWidth = $('#halfQesWidth');
    	var halfQesQuantity = $('#halfQesQuantity');
    	if(hasHalfQes.attr('checked'))
    	{
    		halfQesVal.attr('readonly', false);
    		halfQesWidth.attr('disabled', false);
    		halfQesQuantity.attr('disabled', false);
    	}
    	else
    	{
    		halfQesVal.val('');
    		halfQesVal.attr('readonly', true);
    		halfQesWidth.attr('disabled', true);
    		halfQesQuantity.attr('disabled', true);
    	}
    }
    
    function ctTypeChange()
    {
    	var ctType = $('#ctType');
    	var halfQesTr = $('#halfQesTr');
    	if('codeTable' == ctType.val())
    	{
    		halfQesTr.css('display', 'block');
    	}
    	else if('groupQes' == ctType.val())
    	{
    		halfQesTr.css('display', 'none');
    		var hasHalfQes = $('#hasHalfQes');
    		var halfQesVal = $('#halfQesVal');
    		hasHalfQes.attr('checked', false);
    		halfQesClick();
    	}
    }
    </script>
  </body>
</html>
